home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_q_t / stsbar12.zip / SBTEST.C < prev    next >
Text File  |  1991-10-07  |  16KB  |  446 lines

  1. //===========================================================================
  2. //
  3. //  Program          : SBTEST.C
  4. //  Version          : 1.2.0
  5. //  Operating System : DOS / Windows 3.0 / Microsoft C 6.0
  6. //  Author           : Jean-Marc Krikorian
  7. //                     525 Sandy Lane 
  8. //                     Libertyville, IL  60048 
  9. //                     (708) 816-3314 
  10. // 
  11. //  Copyright 1991 Jean-Marc Krikorian. All Rights Reserved.
  12. // 
  13. //===========================================================================
  14.  
  15. #include "windows.h"  
  16. #include "sbtest.h"  
  17. #include "stsbar.ext"
  18.  
  19. #define ID_STATUSBAR 2000
  20.  
  21. HANDLE hInst;
  22. HWND   hWndStatusBar = 0;
  23. HMENU  hMenu = 0;
  24. WORD   wTextAttributes = 0;
  25. WORD   wCurrentFaceColor = 0;
  26. WORD   wCurrentFaceStyle = 0;
  27. WORD   wCurrentTextColor = 0;
  28. WORD   wCurrentTextFont = 0;
  29. BOOL   bStatusBarVisible = FALSE;
  30. WORD   ypos = 0;
  31.  
  32. HANDLE hLib = NULL;  // stores the handle to the Status Bar DLL 
  33.  
  34. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  35. {
  36.   MSG msg;                  
  37.  
  38.   if (!hPrevInstance)            
  39.       if (!InitApplication(hInstance)) 
  40.         return (FALSE);        
  41.  
  42.   if (!InitInstance(hInstance, nCmdShow))
  43.       return (FALSE);
  44.  
  45.   while (GetMessage(&msg, NULL, NULL,    NULL)) 
  46.   {
  47.       TranslateMessage(&msg);    
  48.       DispatchMessage(&msg);    
  49.   }
  50.  
  51.   return (msg.wParam);    
  52. }
  53.  
  54. BOOL InitApplication(HANDLE hInstance)
  55. {
  56.   WNDCLASS  wc;
  57.  
  58.   wc.style         = NULL;                 
  59.   wc.lpfnWndProc   = MainWndProc;    
  60.   wc.cbClsExtra    = 0;               
  61.   wc.cbWndExtra    = 0;               
  62.   wc.hInstance     = hInstance;        
  63.   wc.hIcon         = LoadIcon(hInstance, "SBTestIcon");
  64.   wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  65.   wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  66.   wc.lpszMenuName  = "SBTestMenu";   
  67.   wc.lpszClassName = "SBTestWClass"; 
  68.  
  69.   return (RegisterClass(&wc));
  70. }
  71.  
  72. BOOL InitInstance(HANDLE hInstance, int nCmdShow)
  73. {
  74.   HWND   hWnd;
  75.  
  76.   hInst = hInstance;
  77.  
  78.   hWnd = CreateWindow("SBTestWClass",                
  79.                       "Status Bar Test Application",   
  80.                       WS_OVERLAPPEDWINDOW,            
  81.                       CW_USEDEFAULT,                  
  82.                       CW_USEDEFAULT,                  
  83.                       CW_USEDEFAULT,                  
  84.                       CW_USEDEFAULT,                  
  85.                       NULL,                           
  86.                       NULL,                           
  87.                       hInstance,                      
  88.                       NULL);
  89.  
  90.   if (!hWnd)
  91.     return (FALSE);
  92.  
  93.   hLib = LoadLibrary("STSBAR.DLL");
  94.  
  95.   ypos = 10;
  96.  
  97.   // Create the status bar window
  98.   hWndStatusBar = CreateWindow("StatusBarClass",
  99.                                NULL,
  100.                                WS_CHILD | SBS_BOTTOM | WS_VISIBLE,
  101.                                0,ypos,0,0,
  102.                                hWnd,
  103.                                ID_STATUSBAR,
  104.                                hInst,
  105.                                NULL);
  106.  
  107.   if (!hWndStatusBar)
  108.   {
  109.     FreeLibrary(hLib);
  110.     return (FALSE);
  111.   }
  112.  
  113.   // this is now the default if the monitor is VGA or better
  114. //  SendMessage(hWndStatusBar, SBM_FACESTYLE, 0, (LONG)SBFS_3DFACE);
  115.   wCurrentFaceStyle = IDM_SB3DFACE;
  116.   CheckMenuItem(hMenu, wCurrentFaceStyle, MF_CHECKED);
  117.  
  118.   // this is now the default if the monitor is VGA or better
  119. //  SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_GRAY);
  120.   wCurrentFaceColor = IDM_SBGRAYFACE;
  121.   CheckMenuItem(hMenu, wCurrentFaceColor, MF_CHECKED);
  122.  
  123.   SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_BLACK);
  124.   wCurrentTextColor = IDM_SBBLACKTEXT;
  125.   CheckMenuItem(hMenu, wCurrentTextColor, MF_CHECKED);
  126.  
  127.   wCurrentTextFont = IDM_SBDEFAULTSYSTEM;
  128.   CheckMenuItem(hMenu, wCurrentTextFont, MF_CHECKED);
  129.  
  130.   bStatusBarVisible = TRUE;
  131.   CheckMenuItem(hMenu, IDM_SBSHOW, MF_CHECKED);
  132.  
  133.   ShowWindow(hWndStatusBar, SW_SHOW);
  134.  
  135.   ShowWindow(hWnd, nCmdShow);  
  136.   UpdateWindow(hWnd);          
  137.  
  138.   return (TRUE);    
  139. }
  140.  
  141. long FAR PASCAL MainWndProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam)
  142. {
  143.   static char    SText[80];
  144.          LOGFONT lf;
  145.  
  146.   switch (message)
  147.   {
  148.     case WM_CREATE:
  149.       hMenu = GetMenu(hWnd);
  150.       wsprintf(SText, "%s%d", (LPSTR)"This is the Status Bar...", GetWindowWord(hWnd, GWW_HINSTANCE));
  151.       return 0;
  152.  
  153.       case WM_COMMAND:
  154.     {
  155.       switch (wParam)
  156.       {
  157.           case IDM_SBSHOW:
  158.           bStatusBarVisible = TRUE;
  159.           CheckMenuItem(hMenu, IDM_SBSHOW, MF_CHECKED);
  160.           CheckMenuItem(hMenu, IDM_SBHIDE, MF_UNCHECKED);
  161.           ShowWindow(hWndStatusBar, SW_SHOW);
  162.           return 0;
  163.  
  164.         case IDM_SBHIDE:
  165.           bStatusBarVisible = FALSE;
  166.           CheckMenuItem(hMenu, IDM_SBHIDE, MF_CHECKED);
  167.           CheckMenuItem(hMenu, IDM_SBSHOW, MF_UNCHECKED);
  168.           ShowWindow(hWndStatusBar, SW_HIDE);
  169.           return 0;
  170.  
  171.         case IDM_SBDISPLAYTEXT:
  172.           SendMessage(hWndStatusBar, SBM_DISPLAYTEXT, wTextAttributes, (LONG)(LPSTR)SText);
  173.               return 0;
  174.  
  175.           case IDM_SB3DFACE:
  176.           CheckMenuItem(hMenu, wCurrentFaceStyle, MF_UNCHECKED);
  177.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  178.           wCurrentFaceStyle = wParam;
  179.           SendMessage(hWndStatusBar, SBM_FACESTYLE, 0, (LONG)SBFS_3DFACE);
  180.           return 0;
  181.  
  182.           case IDM_SB2DFACE:
  183.           CheckMenuItem(hMenu, wCurrentFaceStyle, MF_UNCHECKED);
  184.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  185.           wCurrentFaceStyle = wParam;
  186.           SendMessage(hWndStatusBar, SBM_FACESTYLE, 0, (LONG)SBFS_2DFACE);
  187.           return 0;
  188.  
  189.           case IDM_SBFLATFACE:
  190.           CheckMenuItem(hMenu, wCurrentFaceStyle, MF_UNCHECKED);
  191.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  192.           wCurrentFaceStyle = wParam;
  193.           SendMessage(hWndStatusBar, SBM_FACESTYLE, 0, (LONG)SBFS_FLATFACE);
  194.           return 0;
  195.  
  196.           case IDM_SBGRAYFACE:
  197.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  198.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  199.           wCurrentFaceColor = wParam;
  200.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_GRAY);
  201.           return 0;
  202.  
  203.           case IDM_SBBLACKFACE:
  204.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  205.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  206.           wCurrentFaceColor = wParam;
  207.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_BLACK);
  208.           return 0;
  209.  
  210.           case IDM_SBWHITEFACE:
  211.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  212.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  213.           wCurrentFaceColor = wParam;
  214.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_WHITE);
  215.           return 0;
  216.  
  217.           case IDM_SBREDFACE:
  218.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  219.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  220.           wCurrentFaceColor = wParam;
  221.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_RED);
  222.           return 0;
  223.  
  224.           case IDM_SBGREENFACE:
  225.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  226.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  227.           wCurrentFaceColor = wParam;
  228.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_GREEN);
  229.           return 0;
  230.  
  231.           case IDM_SBBLUEFACE:
  232.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  233.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  234.           wCurrentFaceColor = wParam;
  235.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_BLUE);
  236.           return 0;
  237.  
  238.         case IDM_SBHELV8:
  239.           CheckMenuItem(hMenu, wCurrentTextFont, MF_UNCHECKED);
  240.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  241.           wCurrentTextFont = wParam;
  242.           lf.lfHeight = 8;
  243.           lf.lfWidth = 0;          // this field is ignored
  244.           lf.lfEscapement = 0;     // this field is ignored
  245.           lf.lfOrientation = 0;    // this field is ignored
  246.           lf.lfWeight = 0;         // this field is ignored
  247.           lf.lfItalic = 0;         // this field is ignored
  248.           lf.lfUnderline = 0;      // this field is ignored
  249.           lf.lfStrikeOut = 0;      // this field is ignored
  250.           lf.lfCharSet = 0;        // this field is ignored
  251.           lf.lfOutPrecision = 0;   // this field is ignored
  252.           lf.lfClipPrecision = 0;  // this field is ignored
  253.           lf.lfQuality = 0;        // this field is ignored
  254.           lf.lfPitchAndFamily = 0; // this field is ignored
  255.           lstrcpy (lf.lfFaceName, "Helv");
  256.           SendMessage(hWndStatusBar, SBM_SETFONT, ypos, (LONG)(LPLOGFONT)&lf);
  257.           return 0;
  258.  
  259.         case IDM_SBARIAL25:
  260.           CheckMenuItem(hMenu, wCurrentTextFont, MF_UNCHECKED);
  261.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  262.           wCurrentTextFont = wParam;
  263.           lf.lfHeight = 25;
  264.           lf.lfWidth = 0;          // this field is ignored
  265.           lf.lfEscapement = 0;     // this field is ignored
  266.           lf.lfOrientation = 0;    // this field is ignored
  267.           lf.lfWeight = 0;         // this field is ignored
  268.           lf.lfItalic = 0;         // this field is ignored
  269.           lf.lfUnderline = 0;      // this field is ignored
  270.           lf.lfStrikeOut = 0;      // this field is ignored
  271.           lf.lfCharSet = 0;        // this field is ignored
  272.           lf.lfOutPrecision = 0;   // this field is ignored
  273.           lf.lfClipPrecision = 0;  // this field is ignored
  274.           lf.lfQuality = 0;        // this field is ignored
  275.           lf.lfPitchAndFamily = 0; // this field is ignored
  276.           lstrcpy (lf.lfFaceName, "Arial");
  277.           SendMessage(hWndStatusBar, SBM_SETFONT, ypos, (LONG)(LPLOGFONT)&lf);
  278.           return 0;
  279.  
  280.         case IDM_SBTMS12:
  281.           CheckMenuItem(hMenu, wCurrentTextFont, MF_UNCHECKED);
  282.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  283.           wCurrentTextFont = wParam;
  284.           lf.lfHeight = 12;
  285.           lf.lfWidth = 0;          // this field is ignored
  286.           lf.lfEscapement = 0;     // this field is ignored
  287.           lf.lfOrientation = 0;    // this field is ignored
  288.           lf.lfWeight = 0;         // this field is ignored
  289.           lf.lfItalic = 0;         // this field is ignored
  290.           lf.lfUnderline = 0;      // this field is ignored
  291.           lf.lfStrikeOut = 0;      // this field is ignored
  292.           lf.lfCharSet = 0;        // this field is ignored
  293.           lf.lfOutPrecision = 0;   // this field is ignored
  294.           lf.lfClipPrecision = 0;  // this field is ignored
  295.           lf.lfQuality = 0;        // this field is ignored
  296.           lf.lfPitchAndFamily = 0; // this field is ignored
  297.           lstrcpy (lf.lfFaceName, "Tms");
  298.           SendMessage(hWndStatusBar, SBM_SETFONT, ypos, (LONG)(LPLOGFONT)&lf);
  299.           return 0;
  300.  
  301.         case IDM_SBDEFAULTSYSTEM:
  302.           CheckMenuItem(hMenu, wCurrentTextFont, MF_UNCHECKED);
  303.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  304.           wCurrentTextFont = wParam;
  305.           SendMessage(hWndStatusBar, SBM_SETFONT, ypos, 0L);
  306.           return 0;
  307.  
  308.           case IDM_SBGRAYTEXT:
  309.           CheckMenuItem(hMenu, wCurrentTextColor, MF_UNCHECKED);
  310.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  311.           wCurrentTextColor = wParam;
  312.           SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_GRAY);
  313.           return 0;
  314.  
  315.           case IDM_SBBLACKTEXT:
  316.           CheckMenuItem(hMenu, wCurrentTextColor, MF_UNCHECKED);
  317.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  318.           wCurrentTextColor = wParam;
  319.           SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_BLACK);
  320.           return 0;
  321.  
  322.           case IDM_SBWHITETEXT:
  323.           CheckMenuItem(hMenu, wCurrentTextColor, MF_UNCHECKED);
  324.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  325.           wCurrentTextColor = wParam;
  326.           SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_WHITE);
  327.           return 0;
  328.  
  329.           case IDM_SBREDTEXT:
  330.           CheckMenuItem(hMenu, wCurrentTextColor, MF_UNCHECKED);
  331.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  332.           wCurrentTextColor = wParam;
  333.           SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_RED);
  334.           return 0;
  335.  
  336.           case IDM_SBGREENTEXT:
  337.           CheckMenuItem(hMenu, wCurrentTextColor, MF_UNCHECKED);
  338.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  339.           wCurrentTextColor = wParam;
  340.           SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_GREEN);
  341.           return 0;
  342.  
  343.           case IDM_SBBLUETEXT:
  344.           CheckMenuItem(hMenu, wCurrentTextColor, MF_UNCHECKED);
  345.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  346.           wCurrentTextColor = wParam;
  347.           SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_BLUE);
  348.           return 0;
  349.  
  350.           case IDM_SBBOLD:
  351.           if (GetMenuState(hMenu, wParam, MF_BYCOMMAND) == MF_CHECKED)
  352.           {
  353.             CheckMenuItem(hMenu, wParam, MF_UNCHECKED);
  354.             wTextAttributes = wTextAttributes & ~SBTA_BOLD;
  355.           }
  356.           else
  357.           {
  358.             CheckMenuItem(hMenu, wParam, MF_CHECKED);
  359.             wTextAttributes = wTextAttributes | SBTA_BOLD;
  360.           }
  361.  
  362.           SendMessage(hWndStatusBar, SBM_DISPLAYTEXT, wTextAttributes, (LONG)(LPSTR)SText);
  363.           return 0;
  364.  
  365.           case IDM_SBITALICS:
  366.           if (GetMenuState(hMenu, wParam, MF_BYCOMMAND) == MF_CHECKED)
  367.           {
  368.             CheckMenuItem(hMenu, wParam, MF_UNCHECKED);
  369.             wTextAttributes = wTextAttributes & ~SBTA_ITALICS;
  370.           }
  371.           else
  372.           {
  373.             CheckMenuItem(hMenu, wParam, MF_CHECKED);
  374.             wTextAttributes = wTextAttributes | SBTA_ITALICS;
  375.           }
  376.  
  377.           SendMessage(hWndStatusBar, SBM_DISPLAYTEXT, wTextAttributes, (LONG)(LPSTR)SText);
  378.           return 0;
  379.  
  380.           case IDM_SBUNDERLINE:
  381.           if (GetMenuState(hMenu, wParam, MF_BYCOMMAND) == MF_CHECKED)
  382.           {
  383.             CheckMenuItem(hMenu, wParam, MF_UNCHECKED);
  384.             wTextAttributes = wTextAttributes & ~SBTA_UNDERLINE;
  385.           }
  386.           else
  387.           {
  388.             CheckMenuItem(hMenu, wParam, MF_CHECKED);
  389.             wTextAttributes = wTextAttributes | SBTA_UNDERLINE;
  390.           }
  391.  
  392.           SendMessage(hWndStatusBar, SBM_DISPLAYTEXT, wTextAttributes, (LONG)(LPSTR)SText);
  393.           return 0;
  394.  
  395.           case IDM_SBSTRIKEOUT:
  396.           if (GetMenuState(hMenu, wParam, MF_BYCOMMAND) == MF_CHECKED)
  397.           {
  398.             CheckMenuItem(hMenu, wParam, MF_UNCHECKED);
  399.             wTextAttributes = wTextAttributes & ~SBTA_STRIKEOUT;
  400.           }
  401.           else
  402.           {
  403.             CheckMenuItem(hMenu, wParam, MF_CHECKED);
  404.             wTextAttributes = wTextAttributes | SBTA_STRIKEOUT;
  405.           }
  406.  
  407.           SendMessage(hWndStatusBar, SBM_DISPLAYTEXT, wTextAttributes, (LONG)(LPSTR)SText);
  408.           return 0;
  409.  
  410.         case ID_STATUSBAR:
  411.           switch (HIWORD(lParam))
  412.           {
  413.             case SBN_LBUTTONUP:
  414.               MessageBeep(0);
  415.               return 0;
  416.  
  417.             case SBN_LBUTTONDBLCLK:
  418.               MessageBox(hWnd, "Left Mouse Button Double-Click", "Status Bar Test", MB_OK);
  419.               return 0;
  420.  
  421.             case SBN_RBUTTONUP:
  422.               MessageBeep(0);
  423.               return 0;
  424.  
  425.             case SBN_RBUTTONDBLCLK:
  426.               MessageBox(hWnd, "Right Mouse Button Double-Click", "Status Bar Test", MB_OK);
  427.               return 0;
  428.           }
  429.       }
  430.     }
  431.     return 0;
  432.  
  433.     case WM_DESTROY:
  434.       FreeLibrary(hLib);
  435.       PostQuitMessage(0);
  436.       return 0;
  437.  
  438.     case WM_SIZE:
  439.       if (hWndStatusBar)
  440.         SendMessage(hWndStatusBar, SBM_SIZE, ypos, lParam);
  441.       return 0;
  442.   }
  443.  
  444.   return (DefWindowProc(hWnd, message, wParam, lParam));
  445. }
  446.